// 首先创建一个统一的消息提示工具
import { toastController } from '@ionic/vue';

// 创建一个工具函数
export const showToast = async (
  message: string,
  type: 'success' | 'info' | 'warning' | 'error' = 'info',
  duration: number = 2000
) => {
  // 根据类型设置颜色
  const colorMap = {
    success: 'success',
    info: 'primary',
    warning: 'warning',
    error: 'danger'
  };

  // 创建 toast
  const toast = await toastController.create({
    message: message,
    duration: duration,
    position: 'top', // 可以是 'top', 'middle', 'bottom'
    color: colorMap[type],
    cssClass: `toast-${type}`,
    buttons: [
      {
        icon: 'close',
        role: 'cancel'
      }
    ]
  });

  // 显示 toast
  await toast.present();
};

// 为了方便使用，可以创建具体类型的方法
export const Toast = {
  success: (message: string, duration?: number) => showToast(message, 'success', duration),
  info: (message: string, duration?: number) => showToast(message, 'info', duration),
  warning: (message: string, duration?: number) => showToast(message, 'warning', duration),
  error: (message: string, duration?: number) => showToast(message, 'error', duration)
};